package com.example.myapplication;

import android.Manifest;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;

import com.base.core.EmptyUtils;
import com.base.core.config.DefalutSp;
import com.hjq.toast.ToastUtils;
import com.tbruyelle.rxpermissions2.RxPermissions;

import java.util.UUID;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import io.reactivex.functions.Consumer;

public class LauncherActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        if (!this.isTaskRoot()) {  //解决第一次安装点击home键后再点击app图标重复启动的bug
            if (getIntent().hasCategory(Intent.CATEGORY_LAUNCHER) && getIntent().getAction() == Intent.ACTION_MAIN) {
                finish();
                return;
            }
        }
        setContentView(R.layout.activity_splan);

        new RxPermissions(this).request(Manifest.permission.READ_PHONE_STATE,
                Manifest.permission.READ_EXTERNAL_STORAGE).subscribe(new Consumer<Boolean>() {
            @Override
            public void accept(Boolean aBoolean) throws Exception {
                if (aBoolean) {
                    initUI();
                } else {
                    ToastUtils.show("请打开权限");
                }
            }
        });


    }

    public void initUI() {
       /* String jianting = UUIDUtils.checkUUIDFileByUri(this);
        if (EmptyUtils.isEmpty(jianting)) {
            UUIDUtils.creatUUIDFile(this);
        }*/


        final long start = System.currentTimeMillis();
        while (true) {
            if (System.currentTimeMillis() - start >= 2500) {
                startActivity(new Intent(this, LoginActivity.class));
                break;
            } else {
                try {
                    Thread.sleep(300);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

    }


}
